﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using SailHero.Soft.FrameWork.Models;


namespace UI.Web.SL.Demo.SysAdmin.Common
{
    public static class ViewUtility
    {
        private static Dictionary<string,Type> typeDic;
        public static List<MenuInfo> AllMenu;
        public static IEnumerable<MenuInfo> AllMenuEntites;
        static ViewUtility()
        {
            typeDic = new Dictionary<string, Type>();
        }
        public static void Alert(string msg)
        {
            MessageBox.Show(msg, "系统提示", MessageBoxButton.OK);
        }
        public static MessageBoxResult Ask(string msg)
        {
            return MessageBox.Show(msg, "系统提示", MessageBoxButton.OKCancel);
        }
        public static Color ReturnColorFromString(string color)
        {
            string alpha = color.Substring(0, 2);
            string red = color.Substring(2, 2);
            string green = color.Substring(4, 2);
            string blue = color.Substring(6, 2);
            byte alphaByte = Convert.ToByte(alpha, 16);
            byte redByte = Convert.ToByte(red, 16);
            byte greenByte = Convert.ToByte(green, 16);
            byte blueByte = Convert.ToByte(blue, 16);
            return Color.FromArgb(alphaByte, redByte, greenByte, blueByte);
        }
        public static Control CreatePage(string typeStr)
        {
            Control result;
            var ass = Application.Current.GetType().Assembly;
            if (!typeDic.ContainsKey(typeStr))
            {
                var t = ass.GetType(typeStr);
                typeDic.Add(typeStr, t);
            }
            result = Activator.CreateInstance(typeDic[typeStr]) as Control;
            return result;
        }
        public static IEnumerable<DependencyObject> GetVisuals(this DependencyObject root)
        {
            int count = VisualTreeHelper.GetChildrenCount(root);
            for (int i = 0; i < count; i++)
            {
                var child = VisualTreeHelper.GetChild(root, i);
                yield return child;
                foreach (var descendants in child.GetVisuals())
                {
                    yield return descendants;
                }
            }
        }
    }

}
